<template>
    <div class="item-container">
    <h3>课程质量分布</h3>
    <div ref="compareChart" class="chart-container"></div>
</div>
</template>

<script>
import * as echarts from 'echarts';

export default {
    name: '课程质量分布',
    props: {
        classroomId: {
            type: String,
            required: true
        }
    },
    data() {
        return {
            //暂时填充的数据，后续可通过接口获取
            courses: [
                { name: '在线实训', Excelent: 80, Good: 85,Normal:30 },
                { name: '就业培训', Excelent: 78, Good: 75,Normal:30 },
                { name: '技能提升', Excelent: 67, Good: 65,Normal:30 },
                { name: '师资培训', Excelent: 90, Good: 82,Normal:30 },
                { name: '大数据推荐课程', Excelent: 78, Good: 92,Normal:30 },
            ]
        };
    },
    methods: {
        initCompareChart() {
            const chartDom = this.$refs.compareChart;
            const myChart = echarts.init(chartDom);
            const option = {
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'shadow'
                    }
                },
                legend: {
                    data: ['优秀', '良好','一般']
                },
                xAxis: {
                    type: 'category',
                    data: this.courses.map(course => course.name)
                },
                yAxis: {
                    type: 'value'
                },
                series: [
                    {
                        name: '优秀',
                        type: 'bar',
                        data: this.courses.map(course => course.Excelent),
                        emphasis: {
                            focus: 'series'
                        },
                        markLine: {
                            data: [{ type: 'average', name: '平均值' }]
                        }
                    },
                    {
                        name: '良好',
                        type: 'bar',
                        data: this.courses.map(course => course.Good),
                        emphasis: {
                            focus: 'series'
                        },
                        markLine: {
                            data: [{ type: 'average', name: '平均值' }]
                        }
                    },
                    {
                        name: '一般',
                        type: 'bar',
                        data: this.courses.map(course => course.Normal),
                        emphasis: {
                            focus: 'series'
                        },
                        markLine: {
                            data: [{ type: 'average', name: '平均值' }]
                        }
                    }
                ]
            };
            myChart.setOption(option);
        },
        fetchCourseData() {
            //从后端通过班级ID获取课程均分
        }
    },
    mounted() {
        this.initCompareChart();
        this.fetchCourseData();
    }
};
</script>

<style>
.chart-container {
    width: 100%;
    height: 40vh;
}
</style>